class Solution {
public:
    int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {
        map<int, int> map;
        int sum = 0;

        for(int i = 0; i < nums1.size(); ++i) {
            for(int j = 0; j < nums2.size(); ++j) {
                int temp = nums1[i] + nums2[j];
                auto iterator = map.find(temp);
                if(iterator != map.end()){
                    iterator->second = iterator->second + 1;
                } else {
                    map.insert({temp, 1});
                }
            }
        }

        for(int i = 0; i < nums3.size(); ++i) {
            for(int j = 0; j < nums4.size(); ++j) {
                int temp = - (nums3[i] + nums4[j]);
                auto iterator = map.find(temp);
                sum += iterator->second;
            }
        }

        return sum;
    }
};